package data_structure.mooc;

import data_structure.implement.StackImp;

public class LinkedListStack<E> implements StackImp<E> {

    private LinkedList<E>stack;

    public LinkedListStack(){
        stack = new LinkedList<E> ();
    }
    @Override
    public void push(E e) {
        stack.addFirst (e);
    }

    @Override
    public E pop() {
        return stack.removeFirst ();
    }

    @Override
    public E peek() {
        return stack.getFirst ();
    }

    @Override
    public boolean isEmpty() {
        return stack.isEmpty();
    }

    @Override
    public int getSize() {
        return stack.getSize ();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append ("stack: top ");
        sb.append(stack);
        return sb.toString();
    }
    public static void main(String[] args) {
        LinkedListStack<Integer>stack=new LinkedListStack<> ();

        for(int i=0;i<4;i++){
            stack.push (i);
            System.out.println(stack.toString ());
        }
        stack.pop ();
        System.out.println(stack.toString());
        System.out.println(stack.toString());
    }
}
